<?php
	/**
	 * 内容数据模型
	 * detail description
	 * @todo
	 * @author swingcoder <swingcoder@msn.com>
	 * @version 0.1
	 * @copyright Copyright (c) 2009, swingcoder.com
	 */

	class html_module
	{
		function html_module()
		{
		}

		/**
		 * 基本数据模型
		 * detail description
		 * @param string user
		 * @param integer id
		 * @return int|string|array|object|mixed
		 */
		function base(  )
		{
			return array(
				array( 'cname' => '短标题', 'ename' => 'title_short', 'type' => 'text', 'max_size' => 100, 'column_size' => 45, 'tips' => '必填' , 'required' => 1 , 'default' => '' ),
				array( 'cname' => '长标题', 'ename' => 'title_full', 'type' => 'text', 'max_size' => 100, 'column_size' => 60, 'tips' => '必填' , 'required' => 1 , 'default' => '' ),
				array( 'cname' => '摘要', 'ename' => 'desc', 'type' => 'textarea', 'max_size' => 100, 'column_size' => 80, 'cols' => 60, 'rows' => 2, 'tips' => '' , 'required' => 0, 'default' => '', 'wysiwyg' => 0 ),
				array( 'cname' => '短标题颜色', 'ename' => 'title_short_color', 'type' => 'text', 'max_size' => 10, 'column_size' => 7, 'tips' => '' , 'required' => 0 , 'default' => '#e7497a' ),
				array( 'cname' => '关键词', 'ename' => 'keyword', 'type' => 'text', 'max_size' => 10, 'column_size' => 30, 'tips' => '必填,逗号分隔关键词' , 'required' => 1 , 'default' => '' ),
				array( 'cname' => '假点击数', 'ename' => 'fake_click', 'type' => 'text', 'max_size' => 11, 'column_size' => 10, 'tips' => '' , 'required' => 1 , 'default' => '1' ),
				array( 'cname' => '推荐到首页', 'ename' => 'home_promote_flag', 'type' => 'checkbox', 'max_size' => 10, 'column_size' => 30, 'tips' => '' , 'required' => 0 , 'default' => '' ),
				array( 'cname' => '首页排序', 'ename' => 'home_order_num', 'type' => 'text', 'max_size' => 10, 'column_size' => 5, 'tips' => '' , 'required' => 0 , 'default' => '1' ),
				array( 'cname' => '推荐到栏目首页', 'ename' => 'node_promote_flag', 'type' => 'checkbox', 'max_size' => 10, 'column_size' => 30, 'tips' => '' , 'required' => 0 , 'default' => '' ),
				array( 'cname' => '栏目首页排序', 'ename' => 'node_order_num', 'type' => 'text', 'max_size' => 10, 'column_size' => 5, 'tips' => '' , 'required' => 0 , 'default' => '1' ),
				array( 'cname' => '推荐到列表页', 'ename' => 'list_promote_flag', 'type' => 'checkbox', 'max_size' => 10, 'column_size' => 30, 'tips' => '' , 'required' => 0 , 'default' => '' ),
				array( 'cname' => '列表页排序', 'ename' => 'list_order_num', 'type' => 'text', 'max_size' => 10, 'column_size' => 5, 'tips' => '' , 'required' => 0 , 'default' => '1' ),
				array( 'cname' => '预览图', 'ename' => 'preview_img_path', 'type' => 'file', 'max_size' => 10, 'column_size' => 30, 'tips' => '' , 'required' => 0 , 'default' => '' )
			);
		}

		/**
		 * 新闻数据模型
		 * detail description
		 * @param string user
		 * @param integer id
		 * @return int|string|array|object|mixed
		 */
		function news(  )
		{
			return array(
				array( 'cname' => '来源', 'ename' => 'referer', 'type' => 'text', 'max_size' => 100, 'column_size' => 45, 'tips' => '' , 'required' => 0 , 'default' => '' ),
				array( 'cname' => '作者', 'ename' => 'author', 'type' => 'text', 'max_size' => 100, 'column_size' => 10, 'tips' => '' , 'required' => 0 , 'default' => '' ),
				array( 'cname' => '编辑', 'ename' => 'editor', 'type' => 'text', 'max_size' => 100, 'column_size' => 10, 'tips' => '' , 'required' => 0 , 'default' => '' ),
				array( 'cname' => '内容', 'ename' => 'content', 'type' => 'textarea', 'max_size' => 100, 'cols' => 60, 'rows' => 30, 'tips' => '必填' , 'required' => 1 , 'default' => '', 'wysiwyg' => 1 )
			);
		}

		/**
		 * 相册数据模型
		 * detail description
		 * @param string user
		 * @param integer id
		 * @return int|string|array|object|mixed
		 */
		function photo(  )
		{
			return array(
				array( 'cname' => '相片文件', 'ename' => 'photo', 'type' => 'file', 'max_size' => 100, 'column_size' => 45, 'tips' => '必填,支持格式jpg,png,gif' , 'required' => 1, 'default' => '' ),
			);
		}

		/**
		 * 视频数据模型
		 * detail description
		 * @param string user
		 * @param integer id
		 * @return int|string|array|object|mixed
		 */
		function video(  )
		{
			return array(
				array( 'cname' => '视频文件', 'ename' => 'video', 'type' => 'file', 'max_size' => 100, 'column_size' => 45, 'tips' => '必填' , 'required' => 1, 'default' => '' )
			);
		}


		/**
		 * 表单界面格式化
		 * detail description
		 * @param string user
		 * @param integer id
		 * @return int|string|array|object|mixed
		 */
		function form_render( $field, $default_value='' )
		{
			$return = '';
			if ( $default_value != '' )
			{
				$field['default'] = $default_value;
			}
			switch ( $field['type'] )
			{
				case 'text':
					$return = '<input type="input" name="' . $field['ename'] . '" id="' . $field['ename'] . '" size="' . $field['column_size'] . '" value="' . $field['default'] . '" /> ' . $field['tips'];
					break;

				case 'textarea':
					$return = '<textarea name="' . $field['ename'] . '" id="' . $field['ename'] . '" cols="' . $field['cols'] . '" rows="'.$field['rows'].'" >' . $field['default'] . '</textarea>' . $field['tips'];
					break;

				case 'radio':
					$return = '<input type="radio" name="' . $field['ename'] . '" id="' . $field['ename'] . '" size="' . $field['column_size'] . '" ' . ( $field['default'] == 1 ? ' checked ' : '' ) . '/> ' . $field['tips'];
					break;

				case 'checkbox':
					$return = '<input type="checkbox" name="' . $field['ename'] . '" id="' . $field['ename'] . '" size="' . $field['column_size'] . '" ' . ( $field['default'] == 1 ? ' checked ' : '' ) . '/> ' . $field['tips'];
					break;

				case 'select':
					$optionstr = '';
					if( isset( $field['option'] ) && is_array( $field['option'] ) )
					{
						$selected = '';
						foreach( $field['option'] as $name => $value )
						{
							if( $value == $fiedl['default'] )
							{
								$selected = ' selected ';
							}
							else
							{
								$selected = '';
							}
							$optionstr .= '<option value="' . $value . '" ' . $selected . '>' . $name . '</option>';
						}
					}
					$return = '<select name="' . $field['ename'] . '" id="' . $field['ename'] . '" >' . $optionstr . '</select>' . $field['tips'];
					break;

				case 'file':
					$return = ( empty( $field['default'] ) ? '' : '<a href="' . config( 'domain.tpl.root' ) . substr( $field['default'], 1) . '" target="_blank">预览文件</a><br />' ) . '<input type="file" name="' . $field['ename'] . '" id="' . $field['ename'] . '" size="' . $field['column_size'] . '" /> ' . $field['tips'];
					break;

				default:
			}

			return $return;
		}
	}

?>